﻿@model YouWei.Infrastructure.Entity.SmsTask
@{
    ViewBag.Title = "短信任务";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header">
    <h1>
        短信任务管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li><a href="#" id="preBtn">短信任务列表</a></li>
        <li class="active">短信任务管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <form class="form-horizontal" id="form1">
                        <div class="box-body">
                            <input type="hidden" name="ID" value="@Model.TaskID" />
                            <div class="form-group">
                                <label class="col-sm-2 control-label">任务名称</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtTaskName" id="txtTaskName" value="@Model.TaskName" class="form-control" maxlength="255">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">品牌</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtCarBrand" id="txtCarBrand" value="@Model.CarBrand" class="form-control" maxlength="11">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">车型</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtCarSerial" id="txtCarSerial" value="@Model.CarSerial" class="form-control">
                                </div>
                            </div>
                            @if (Model.StartDate > DateTime.MinValue)
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">开始时间</label>
                                    <div class="col-sm-3">
                                        <input type="text" value="@Model.StartDate.ToString("yyyy-MM-dd")" name="txtStartDate" autocomplete="off"  id="txtStartDate" class="form-control">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">开始时间</label>
                                    <div class="col-sm-3">
                                        <input type="text" autocomplete="off"  value="" name="txtStartDate" id="txtStartDate" class="form-control">
                                    </div>
                                </div>
                            }
                            @if (Model.EndDate > DateTime.MinValue)
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">结束时间</label>
                                    <div class="col-sm-3">
                                        <input type="text" value="@Model.EndDate.ToString("yyyy-MM-dd")" name="txtEndDate" id="txtEndDate" autocomplete="off"  class="form-control">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">结束时间</label>
                                    <div class="col-sm-3">
                                        <input type="text" value="" autocomplete="off"  name="txtEndDate" id="txtEndDate" class="form-control">
                                    </div>
                                </div>
                            }
                          
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer text-center">
                            <button class="btn btn-info" type="button" id="btnSave">保存</button>
                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>
                <div class="box-footer clearfix ">
                </div>
                <!-- /.box-body -->
                <!-- /.box -->
            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script type="text/javascript">
        var userId = 0; //是否是添加页面，如果是编辑页则判断条件增加ID
        $(document).ready(function () {
            initFormValidate();
            binds();
            $("#txtStartDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
            $("#txtEndDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
        });

        //保存
        function save() {
            var bootstrapValidator = $("#form1").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                var url = '@Url.Action("SaveTask", "Sms")';
                var options = {
                    url: url,
                    type: "POST",
                    data: {
                        TaskID: @Model.TaskID,
                        txtTaskName: $("#txtTaskName").val(),
                        txtCarBrand: $("#txtCarBrand").val(),
                        txtCarSerial: $("#txtCarSerial").val(),
                        txtStartDate: $("#txtStartDate").val(),
                        txtEndDate: $("#txtEndDate").val()
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("保存成功", function () {
                                location.href='@Url.Action("TaskList", "Sms")';
                            });
                        } else {
                            BMCW.alert(o.message);
                        }
                    }
                };

                BMCW.ajax(options);
            }
        }
        function binds() {
            //保存
            $("#btnSave").click(function () {
                save();
            });
            $("#preBtn").click(function () {
                var url = '@Url.Action("TaskList", "Sms")';
                location.href = url;
            })
        }

        function initFormValidate() {
            $("#form1").bootstrapValidator({
                submitHandler: function (valiadtor, loginForm, submitButton) {
                    valiadtor.defaultSubmit();
                },
                fields: {
                    txtTaskName: {
                        validators: {
                            notEmpty: {
                                message: '请输入卡任务名称'
                            }
                        }
                    },
                    txtCarBrand: {
                        validators: {
                            notEmpty: {
                                message: '请输入品牌'
                            }
                        }
                    },
                    txtCarSerial: {
                        validators: {
                            notEmpty: {
                                message: '请输入车型'
                            }
                        }
                    },
                    txtStartDate: {
                        validators: {
                            notEmpty: {
                                message: '请输入开始时间'
                            }

                        }
                    },
                    txtEndDate: {
                        validators: {
                            notEmpty: {
                                message: '请输入结束时间'
                            }

                        }
                    }
                }
            });
        }


    </script>
}




